package com.mlink.vs.action;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.annotation.Resource;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.seasar.struts.annotation.Execute;
import org.seasar.struts.util.ResponseUtil;

import com.google.gson.Gson;
import com.mlink.vs.entity.PiccLatestTaskTime;
import com.mlink.vs.entity.PiccTaskAudio;
import com.mlink.vs.entity.PiccTaskFile;
import com.mlink.vs.entity.PiccTaskPool;
import com.mlink.vs.entity.PiccTaskStatus;
import com.mlink.vs.entity.PiccUser;
import com.mlink.vs.service.DbTimeService;
import com.mlink.vs.service.PiccLatestTaskTimeService;
import com.mlink.vs.service.PiccTaskAudioService;
import com.mlink.vs.service.PiccTaskFileService;
import com.mlink.vs.service.PiccTaskPoolService;
import com.mlink.vs.service.PiccTaskStatusService;
import com.mlink.vs.service.PiccUserOnlineStatusService;
import com.mlink.vs.service.PiccUserService;
import com.mlink.vs.sso.BaseAction;
import com.mlink.vs.util.Constants;
import com.mlink.vs.util.StreamUtil;
import com.mlink.vs.util.ZipUtil;

public class CaseAction<E> {

	/**
	 * request请求对象
	 */
	@Resource
	private HttpServletRequest req;

	/**
	 * response请求对象
	 */
	@Resource
	private HttpServletResponse rep;

	@Resource
	PiccTaskPoolService piccTaskPoolService;

	@Resource
	PiccUserService piccUserService;
	@Resource
	PiccUserOnlineStatusService piccUserOnlineStatusService;
	@Resource
	PiccTaskStatusService piccTaskStatusService;

	@Resource
	PiccTaskFileService piccTaskFileService;
	
	@Resource
	DbTimeService dbTimeService;
	
	@Resource
	PiccTaskAudioService piccTaskAudioService;
	
	@Resource
	PiccLatestTaskTimeService piccLatestTaskTimeService;

	// 确认案件金额接口
	@Execute(validator = false)
	public String submitTaskMoney() {

		Gson gson = new Gson();
		StringBuffer indata = StreamUtil.getRequestBody(req);
		Map<String, String> stsMap = new HashMap<String, String>();

		Map<String, String> mapData = gson.fromJson(indata.toString(), Map.class);
		if (mapData == null)
			return null;

		String taskId = (String) mapData.get("taskId");
		String taskMoney = (String) mapData.get("taskMoney");

		try {
			rep.setCharacterEncoding("utf-8");
			if (StringUtils.isBlank(taskId)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "taskId不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			if (StringUtils.isBlank(taskMoney)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "taskMoney不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			
			if (taskMoney != null && !"".equals(taskMoney.trim())){ 
				Pattern pattern = Pattern.compile("[0-9]+\\.?[0-9]*"); 
				Matcher isNum =pattern.matcher(taskMoney); 
				if (!isNum.matches()) {
					stsMap.put("sts", "2"); stsMap.put("msg", "taskMoney参数错误");
					rep.getWriter().println(gson.toJson(stsMap));
					rep.getWriter().flush(); return null; 
				} 
			}
			
			PiccTaskPool piccTaskPool = piccTaskPoolService.findById(taskId);
			if (null == piccTaskPool) {
				stsMap.put("sts", "2");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			} else {
				piccTaskPool.caseMoney = new BigDecimal(taskMoney);
				//piccTaskPool.taskStatus = Constants.TASK_STATUS_YICL;
				piccTaskPool.updateTime = dbTimeService.getDbTimeStamp();
				piccTaskPoolService.update(piccTaskPool);
				/*PiccTaskStatus piccTaskStatus = new PiccTaskStatus();
				piccTaskStatus.id = UUID.randomUUID().toString().replace("-", "");
				piccTaskStatus.taskId = taskId;
				piccTaskStatus.taskStatus = Constants.TASK_STATUS_YICL;
				piccTaskStatus.createTime = timestamp;
				piccTaskStatusService.insert(piccTaskStatus);*/
				stsMap.put("sts", "0");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

		return null;
	}

	// 获取案件列表接口
	@Execute(validator = false)
	public String fetchCaseList() {
		Gson gson = new Gson();
		StringBuffer indata = StreamUtil.getRequestBody(req);
		Map stsMap = new HashMap<String, String>();

		Map<String, String> mapData = gson.fromJson(indata.toString(), Map.class);
		if (mapData == null)
			return null;
		if (BaseAction.checkToken(indata, rep) == false)
			return null; // 验证token是否有效 无效直接返回错误码-1000

		String userId = (String) mapData.get("userId");
		String pageNum = (String) mapData.get("pageNum");
		String searchKey = (String) mapData.get("searchKey");
		String pageCount = (String) mapData.get("pageCount");
		String optType = (String) mapData.get("optType");
		String token = (String) mapData.get("token");
		try {
			rep.setCharacterEncoding("utf-8");
			if (StringUtils.isBlank(userId)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "userId不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			if (StringUtils.isBlank(optType)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "optType不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}

			if (StringUtils.isBlank(pageNum)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "pageNum不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			if (StringUtils.isBlank(pageCount)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "pageCount不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			int pageCount1 = Integer.parseInt(pageCount);
			int start = (Integer.parseInt(pageNum) - 1) * pageCount1;
			String taskStatus = optType;
			List<PiccTaskPool> PiccTaskPoolList = piccTaskPoolService.findByUserId(userId, taskStatus, searchKey, start,
					pageCount1);
			int totalCount = piccTaskPoolService.findTotalCount(userId, taskStatus, searchKey);
			if (totalCount % pageCount1 == 0) {
				stsMap.put("sumPage", totalCount / pageCount1);
			} else {
				stsMap.put("sumPage", totalCount / pageCount1 + 1);
			}
			stsMap.put("totalCount", totalCount);
			if (null != PiccTaskPoolList && PiccTaskPoolList.size() > 0) {
				stsMap.put("sts", "0");
				List list = new ArrayList();
				for (int i = 0; i < PiccTaskPoolList.size(); i++) {
					Map a = new HashMap();
					DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
					a.put("taskId", PiccTaskPoolList.get(i).taskId);
					a.put("caseNum", PiccTaskPoolList.get(i).caseNumber);
					a.put("carNumber", PiccTaskPoolList.get(i).carNumber);
					String sertId = PiccTaskPoolList.get(i).sertId;
					if(null!=sertId && !"".equals(sertId)){
						a.put("seatUserId", sertId);
						PiccUser piccUser1 = piccUserService.getUserInfo(sertId, token);
						a.put("seatUserName", piccUser1.userName);
					}else{
						a.put("seatUserId", "");
						a.put("seatUserName","");
					}
					a.put("caseType", PiccTaskPoolList.get(i).caseType);
					a.put("dsType", PiccTaskPoolList.get(i).taskType);
					a.put("taskMoney", PiccTaskPoolList.get(i).caseMoney == null ? " " : PiccTaskPoolList.get(i).caseMoney);
					a.put("updateTime", sdf.format(PiccTaskPoolList.get(i).updateTime));
					list.add(a);
				}
				stsMap.put("caseList", list);
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			} else {
				stsMap.put("sts", "2");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			}

		} catch (IOException e) {
			e.printStackTrace();
		}

		return null;
	}

	// 获取在线坐席数接口
	@Execute(validator = false)
	public String fetchSeatNum() {
		Gson gson = new Gson();
		StringBuffer indata = StreamUtil.getRequestBody(req);
		Map<String, String> stsMap = new HashMap<String, String>();

		Map<String, String> mapData = gson.fromJson(indata.toString(), Map.class);
		if (mapData == null)
			return null;

		String userId = (String) mapData.get("userId");
		String groupId = (String) mapData.get("groupId");

		try {
			rep.setCharacterEncoding("utf-8");
			if (StringUtils.isBlank(userId)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "userId不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			if (StringUtils.isBlank(groupId)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "groupId不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}

			/*
			 * PiccTaskPool piccTaskPool =
			 * piccTaskPoolService.findTask(caseNumber, carNumber);
			 * if(null==piccTaskPool){ stsMap.put("sts", "1");
			 * rep.getWriter().println(gson.toJson(stsMap));
			 * rep.getWriter().flush(); }else{ piccTaskPool.caseMoney=new
			 * BigDecimal(taskMoney); piccTaskPoolService.update(piccTaskPool);
			 * stsMap.put("sts", "0");
			 * rep.getWriter().println(gson.toJson(stsMap));
			 * rep.getWriter().flush(); }
			 */
		} catch (IOException e) {
			e.printStackTrace();
		}

		return null;
	}

	// 案件创建接口（视频定损专用）
	@Execute(validator = false)
	public String createCase() {
		Gson gson = new Gson();
		StringBuffer indata = StreamUtil.getRequestBody(req);
		Map<String, String> stsMap = new HashMap<String, String>();

		Map<String, String> mapData = gson.fromJson(indata.toString(), Map.class);
		if (mapData == null)
			return null;
		if (BaseAction.checkToken(indata, rep) == false)
			return null; // 验证token是否有效 无效直接返回错误码-1000

		String userId = (String) mapData.get("userId");
		String caseNumber = (String) mapData.get("caseNumber");
		String carNumber = (String) mapData.get("carNumber");
		String caseType = (String) mapData.get("caseType");
		String lon = (String) mapData.get("lon");
		String lat = (String) mapData.get("lat");
		String address = (String) mapData.get("address");
		String describe = (String) mapData.get("describe");
		String token = (String) mapData.get("token");
		try {
			rep.setCharacterEncoding("utf-8");
			if (StringUtils.isBlank(userId)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "userId不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			if (StringUtils.isBlank(caseNumber)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "caseNumber不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			if (StringUtils.isBlank(carNumber)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "carNumber不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}

			PiccTaskPool piccTaskPool = piccTaskPoolService.findTask(caseNumber, carNumber);
			if (null != piccTaskPool) {
				stsMap.put("sts", "3");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			} else {
				// 往任务主表里添加任务
				PiccTaskPool piccTaskPool2 = new PiccTaskPool();
				piccTaskPool2.taskId = UUID.randomUUID().toString().replace("-", "");
				piccTaskPool2.leadingUserId = userId;
				piccTaskPool2.caseNumber = caseNumber;
				piccTaskPool2.carNumber = carNumber;
				piccTaskPool2.caseType = caseType;
				piccTaskPool2.taskType = Constants.TASK_TYPE_VIDEO;
				piccTaskPool2.lon = lon;
				piccTaskPool2.lat = lat;
				piccTaskPool2.firstNumber=Integer.valueOf(Constants.TASK_DEFAULT_NUMBER);
				piccTaskPool2.address = address;
				piccTaskPool2.taskDescribe = describe;
				PiccUser piccUser = piccUserService.getUserInfo(userId, token);
				piccTaskPool2.groupName = piccUser.groupName;
				Timestamp dbTimeStamp = dbTimeService.getDbTimeStamp();
				piccTaskPool2.createTime = dbTimeStamp;
				piccTaskPool2.updateTime = dbTimeStamp;
				piccTaskPool2.dsNumber=Integer.valueOf(Constants.TASK_DS_NUMBER);
				piccTaskPool2.deleteFlag = false;
				piccTaskPool2.taskStatus= Constants.TASK_STATUS_DAICL;
				piccTaskPoolService.insert(piccTaskPool2);
				
				// 往历史状态添加数据
				PiccTaskStatus piccTaskStatus = new PiccTaskStatus();
				piccTaskStatus.id = UUID.randomUUID().toString().replace("-", "");
				piccTaskStatus.taskId = piccTaskPool2.taskId;
				piccTaskStatus.taskStatus = Constants.TASK_STATUS_DAICL;
				piccTaskStatus.taskType = Constants.TASK_TYPE_VIDEO;
				piccTaskStatus.createTime = dbTimeStamp;
				piccTaskStatusService.insert(piccTaskStatus);
				
				/*String groupName=piccUser.groupName;
				String number0=Constants.TASK_DEFAULT_NUMBER;
				String number1=Constants.TASK_FIRST_NUMBER;
				List<PiccTaskPool> findPaiduiTaskkk = piccTaskPoolService.findPaiduiTaskkk(groupName, number0, number1);
				if(null!=findPaiduiTaskkk&&findPaiduiTaskkk.size()>0){
					piccTaskPool2.taskStatus= Constants.TASK_STATUS_DAICL;
				}
				else{
					//查询哪个在线坐席正在处理的案件量最少 把此案件分配给他
					String userType1=Constants.USER_TYPE_SEAT;
					String userType2=Constants.USER_TYPE_LEADER;
					String taskStatus=Constants.TASK_STATUS_WAIT_APP;
					String taskType = Constants.TASK_TYPE_VIDEO;
					String isOnline = Constants.USER_STATUS_ONLINE;
					List<Map> findPictureTask = piccTaskPoolService.findPictureTask(userId,userType1,userType2,taskStatus,taskType,isOnline);
					Map<String , Object> mapp = findPictureTask.get(0);
					String idd = (String) mapp.get("f1");
					Integer count=new Integer(String.valueOf(mapp.get("countt"))); 
					if(count<new Integer(Constants.MAX_VIDEO)){
						piccTaskPool2.sertId=idd;
						piccTaskPool2.taskStatus=Constants.TASK_STATUS_WAIT_APP;
					}
					else{
						piccTaskPool2.taskStatus= Constants.TASK_STATUS_DAICL;
					}
				}*/
				
				stsMap.put("sts", "0");
				stsMap.put("taskId",piccTaskPool2.taskId);
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

		return null;
	}

	// 获取案件状态接口
	@Execute(validator = false)
	public String fetchZBCaseStatus() {
		Gson gson = new Gson();
		StringBuffer indata = StreamUtil.getRequestBody(req);
		Map<String, String> stsMap = new HashMap<String, String>();

		Map<String, String> mapData = gson.fromJson(indata.toString(), Map.class);
		if (mapData == null)
			return null;
		if (BaseAction.checkToken(indata, rep) == false)
			return null; // 验证token是否有效 无效直接返回错误码-1000

		String taskId = (String) mapData.get("taskId");

		try {
			rep.setCharacterEncoding("utf-8");
			if (StringUtils.isBlank(taskId)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "taskId不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			PiccTaskPool piccTaskPool = piccTaskPoolService.findById(taskId);
			if (null == piccTaskPool) {
				stsMap.put("sts", "1");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			} else {
				stsMap.put("sts", "0");
				stsMap.put("caseStatus", piccTaskPool.taskStatus);
				stsMap.put("seatUserId", piccTaskPool.sertId);
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

		return null;
	}

	// 案件查询接口
	@Execute(validator = false)
	public String searchCaseList() {

		Gson gson = new Gson();
		StringBuffer indata = StreamUtil.getRequestBody(req);
		Map stsMap = new HashMap<String, String>();

		Map<String, String> mapData = gson.fromJson(indata.toString(), Map.class);
		if (mapData == null)
			return null;
		if (BaseAction.checkToken(indata, rep) == false)
			return null; // 验证token是否有效 无效直接返回错误码-1000

		String groupName = (String) mapData.get("groupName");
		String userId = (String) mapData.get("userId");
		String caseNum = (String) mapData.get("caseNumber");
		String carNum = (String) mapData.get("carNumber");
		String caseType = (String) mapData.get("caseType");
		String dsType = (String) mapData.get("dsType");
		String hasMoney = (String) mapData.get("hasMoney");
		String startDate = (String) mapData.get("startDate");
		String endDate = (String) mapData.get("endDate");
		String pageNum = (String) mapData.get("pageNum");
		String pageCount = (String) mapData.get("pageCount");
		String token = (String) mapData.get("token");
		try {
			rep.setCharacterEncoding("utf-8");
			if (StringUtils.isBlank(token)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "token不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			if (StringUtils.isBlank(groupName)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "groupName不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			if (StringUtils.isBlank(pageNum)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "pageNum不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			if (StringUtils.isBlank(pageCount)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "pageCount不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}

			int pageCountt = Integer.parseInt(pageCount);
			int startt = (Integer.parseInt(pageNum) - 1) * pageCountt;
			List<PiccTaskPool> findFetchCaseList = piccTaskPoolService.findFetchCaseList(userId, groupName, caseType,
					dsType, caseNum, carNum,hasMoney, startt, startDate, endDate, pageCountt);
			if (null != findFetchCaseList && findFetchCaseList.size() > 0) {
				int totalCount = piccTaskPoolService.findTotalCountt(userId, groupName, caseType, dsType, caseNum,
						carNum,hasMoney, startDate, endDate);
				if (totalCount % pageCountt == 0) {
					stsMap.put("sumPage", totalCount / pageCountt);
				} else {
					stsMap.put("sumPage", totalCount / pageCountt + 1);
				}
				stsMap.put("totalCount", totalCount);
				stsMap.put("sts", "0");
				List list = new ArrayList();
				for (int i = 0; i < findFetchCaseList.size(); i++) {
					Map<String, String> a = new HashMap<String, String>();
					a.put("taskId", findFetchCaseList.get(i).taskId);
					a.put("caseType", findFetchCaseList.get(i).caseType);
					a.put("dsType", findFetchCaseList.get(i).taskType);
					a.put("caseNum", findFetchCaseList.get(i).caseNumber);
					a.put("carNumber", findFetchCaseList.get(i).carNumber);
					String leadingUserId = findFetchCaseList.get(i).leadingUserId;
					a.put("userId", leadingUserId);
					PiccUser piccUser = piccUserService.getUserInfo(leadingUserId,token);
					a.put("userName", piccUser.userName);
					a.put("userCompany", piccUser.userCompany);
					DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
					a.put("updateTime", sdf.format(findFetchCaseList.get(i).updateTime));
					list.add(a);
				}
				stsMap.put("caseList", list);
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			} else {
				stsMap.put("sts", "2");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

		return null;
	}

	// 更新案件接口
	@Execute(validator = false)
	public String updateCase() {
		Gson gson = new Gson();
		StringBuffer indata = StreamUtil.getRequestBody(req);
		Map<String, String> stsMap = new HashMap<String, String>();

		Map<String, String> mapData = gson.fromJson(indata.toString(), Map.class);
		if (mapData == null)
			return null;
		if (BaseAction.checkToken(indata, rep) == false)
			return null; // 验证token是否有效 无效直接返回错误码-1000

		String taskId = (String) mapData.get("taskId");
		String caseTypee = (String) mapData.get("caseType");
		String dsTypee = (String) mapData.get("dsType");
		String describee = (String) mapData.get("describe");
		String token = (String) mapData.get("token");
		try {
			rep.setCharacterEncoding("utf-8");
			if (StringUtils.isBlank(token)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "token不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			if (StringUtils.isBlank(taskId)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "taskId不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			
			PiccTaskPool piccTaskPool = piccTaskPoolService.findById(taskId);
			if (null == piccTaskPool) {
				stsMap.put("sts", "2");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			} else {
				Timestamp dbTimeStamp = dbTimeService.getDbTimeStamp();
				piccTaskPool.caseType = caseTypee;
				piccTaskPool.taskType = dsTypee;
				piccTaskPool.taskDescribe = describee;
				piccTaskPool.updateTime = dbTimeStamp;
				if (Constants.TASK_STATUS_YAOQZB.equals(piccTaskPool.taskStatus)) {
					piccTaskPool.taskStatus = Constants.TASK_STATUS_YICL;
				}
				piccTaskPoolService.update(piccTaskPool);
				// 往任务历史表里添加
				PiccTaskStatus piccTaskStatus = new PiccTaskStatus();
				piccTaskStatus.id = UUID.randomUUID().toString().replace("-", "");
				piccTaskStatus.taskId = piccTaskPool.taskId;
				piccTaskStatus.taskStatus = piccTaskPool.taskStatus;
				piccTaskStatus.taskType = dsTypee;
				piccTaskStatus.createTime = dbTimeStamp;
				piccTaskStatusService.insert(piccTaskStatus);
				stsMap.put("sts", "0");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

		return null;
	}

	// 添加为增补案件接口
	@Execute(validator = false)
	public String zbCase() {
		Gson gson = new Gson();
		StringBuffer indata = StreamUtil.getRequestBody(req);
		Map<String, String> stsMap = new HashMap<String, String>();

		Map<String, String> mapData = gson.fromJson(indata.toString(), Map.class);
		if (mapData == null)
			return null;
		if (BaseAction.checkToken(indata, rep) == false)
			return null; // 验证token是否有效 无效直接返回错误码-1000

		String taskId = (String) mapData.get("taskId");
		String zbInfo = (String) mapData.get("zbInfo");
		String token = (String) mapData.get("token");
		try {
			rep.setCharacterEncoding("utf-8");
			if (StringUtils.isBlank(token)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "token不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			if (StringUtils.isBlank(taskId)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "taskId不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			PiccTaskPool piccTaskPool = piccTaskPoolService.findById(taskId);
			if (null == piccTaskPool) {
				stsMap.put("sts", "2");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			} else {
				piccTaskPool.taskZbInfo = zbInfo;
				piccTaskPool.taskStatus = Constants.TASK_STATUS_YAOQZB;
				Timestamp dbTimeStamp = dbTimeService.getDbTimeStamp();
				piccTaskPool.updateTime = dbTimeStamp;
				piccTaskPoolService.update(piccTaskPool);
				PiccTaskStatus piccTaskStatus = new PiccTaskStatus();
				piccTaskStatus.id = UUID.randomUUID().toString().replace("-", "");
				piccTaskStatus.taskStatus = Constants.TASK_STATUS_YAOQZB;
				piccTaskStatus.taskType = piccTaskPool.taskType;
				piccTaskStatus.createTime = dbTimeStamp;
				stsMap.put("sts", "0");
				stsMap.put("caseStatus", piccTaskPool.taskStatus);
				stsMap.put("seatUserId", piccTaskPool.sertId);
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

		return null;
	}

	// 案件统计接口
	@Execute(validator = false)
	public String staticCaseList() {
				  
		Gson gson = new Gson();
		StringBuffer indata = StreamUtil.getRequestBody(req);
		Map stsMap = new HashMap<String, String>();

		Map<String, String> mapData = gson.fromJson(indata.toString(), Map.class);
		if (mapData == null)
			return null;
		if (BaseAction.checkToken(indata, rep) == false)
			return null; // 验证token是否有效 无效直接返回错误码-1000

		String groupName = (String) mapData.get("groupName");
		String userId = (String) mapData.get("userId");
		String seatUserId = (String) mapData.get("seatUserId");
		String caseNum = (String) mapData.get("caseNumber");
		String carNum = (String) mapData.get("carNumber");
		String caseType = (String) mapData.get("caseType");
		String dsType = (String) mapData.get("dsType");
		String department = (String) mapData.get("department");
		String startDate = (String) mapData.get("startDate");
		String endDate = (String) mapData.get("endDate");
		String pageNum = (String) mapData.get("pageNum");
		String pageCount = (String) mapData.get("pageCount");
		String token = (String) mapData.get("token");
		try {
			rep.setCharacterEncoding("utf-8");
			if (StringUtils.isBlank(token)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "token不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			if (StringUtils.isBlank(groupName)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "groupName不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			if (StringUtils.isBlank(pageNum)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "pageNum不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			if (StringUtils.isBlank(pageCount)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "pageCount不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}

			int pageCountt = Integer.parseInt(pageCount);
			int startt = (Integer.parseInt(pageNum) - 1) * pageCountt;
			List<Map> findFetchCaseList = piccTaskPoolService.findstaticCaseList(userId, groupName, seatUserId,
					caseType, dsType, caseNum, carNum, department, startt, startDate, endDate, pageCountt);
			int totalCount = piccTaskPoolService.findstaticCaseListTotalCountt(userId, groupName, seatUserId,
					caseType, dsType, caseNum, carNum, department, startDate, endDate);
			if (totalCount % pageCountt == 0) {
				stsMap.put("sumPage", totalCount / pageCountt);
			} else {
				stsMap.put("sumPage", totalCount / pageCountt + 1);
			}
			stsMap.put("totalCount", totalCount);
			if (null != findFetchCaseList && findFetchCaseList.size() > 0) {
				stsMap.put("sts", "0");
				List list = new ArrayList();
				for (int i = 0; i < findFetchCaseList.size(); i++) {
					Map a = new HashMap();
					Map<String, Object> mapp = findFetchCaseList.get(i);
					a.put("taskId", mapp.get("taskId") == null ? "" : mapp.get("taskId"));
					a.put("caseType", mapp.get("caseType") == null ? "" : mapp.get("caseType"));
					a.put("dsType", mapp.get("taskType") == null ? "" : mapp.get("taskType"));
					a.put("caseNumber", mapp.get("caseNumber") == null ? "" : mapp.get("caseNumber"));
					a.put("carNumber", mapp.get("carNumber") == null ? "" : mapp.get("carNumber"));
					String leadingUserId = (String) mapp.get("leadingUserId");
					a.put("userId", leadingUserId);
					PiccUser piccUser = piccUserService.getUserInfo(leadingUserId,token);
					a.put("userName", piccUser.userName == null ? "" : piccUser.userName);
					a.put("userCompany", piccUser.userCompany == null ? "" : piccUser.userCompany);
					String sertId = (String) mapp.get("sertId");
					if(null!=sertId && !"".equals(sertId)){
						a.put("seatUserId", sertId);
						PiccUser piccUser1 = piccUserService.getUserInfo(sertId,token);
						a.put("seatUserName", piccUser1.userName);
					}else{
						a.put("seatUserId", "");
						a.put("seatUserName","");
					}
					DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
					a.put("updateTime", sdf.format(mapp.get("updateTime")));

					list.add(a);
				}
				stsMap.put("caseList", list);
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			} else {
				stsMap.put("sts", "2");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

		return null;
	}

	// 获取部门列表接口(需要重写)
	@Execute(validator = false)
	public String deptList() {

		Gson gson = new Gson();
		// StringBuffer indata = StreamUtil.getRequestBody(req);
		Map stsMap = new HashMap<String, String>();

		// Map<String, String> mapData =
		// gson.fromJson(indata.toString(),Map.class);
		/*
		 * if (mapData == null) return null;
		 */

		try {
			rep.setCharacterEncoding("utf-8");
			List imgs = new ArrayList();
			List<Map> findSectorName = piccUserService.findSectorName();
			for (int i = 0; i < findSectorName.size(); i++) {
				Map piccUser = findSectorName.get(i);
				imgs.add(piccUser.get("dept"));
			}
			stsMap.put("sts", "0");
			stsMap.put("deptList", imgs);
			rep.getWriter().println(gson.toJson(stsMap));
			rep.getWriter().flush();
		} catch (IOException e) {
			e.printStackTrace();
		}

		return null;
	}

	// 获取案件详情接口
	@Execute(validator = false)
	public String caseInfo() {

		ServletContext context = req.getSession().getServletContext();
		final String scFileSavePath = context.getInitParameter("SERVER_URL_FOR_IMAGE");

		if (scFileSavePath == null) {
			// 环境变量未配置，异常退出
			System.out.println("环境变量[SERVER_URL_FOR_IMAGE]未配置，异常退出");
			return null;
		}
		Gson gson = new Gson();
		StringBuffer indata = StreamUtil.getRequestBody(req);
		Map stsMap = new HashMap<String, String>();

		Map<String, String> mapData = gson.fromJson(indata.toString(), Map.class);
		if (mapData == null)
			return null;
		if (BaseAction.checkToken(indata, rep) == false)
			return null; // 验证token是否有效 无效直接返回错误码-1000

		String taskId = (String) mapData.get("taskId");
		String token = (String) mapData.get("token");
		try {
			rep.setCharacterEncoding("utf-8");
			if (StringUtils.isBlank(token)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "token不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			if (StringUtils.isBlank(taskId)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "taskId不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}

			PiccTaskPool piccTaskPool = piccTaskPoolService.findById(taskId);
			if (null == piccTaskPool) {
				stsMap.put("sts", "2");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			} else {
				stsMap.put("sts", "0");
				stsMap.put("taskId", taskId);
				stsMap.put("carNumber", piccTaskPool.carNumber);
				stsMap.put("caseNumber", piccTaskPool.caseNumber);
				stsMap.put("caseType", piccTaskPool.caseType);
				stsMap.put("lastTimeAssessmentType", piccTaskPool.taskType);
				SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				stsMap.put("LastTimeAnswer", df.format(piccTaskPool.updateTime));
				PiccUser piccUser = piccUserService.getUserInfo( piccTaskPool.leadingUserId, token);
				stsMap.put("userId", piccUser.userId);
				stsMap.put("userName", piccUser.userName);
				stsMap.put("userCompany", piccUser.userCompany);
				String sertId = piccTaskPool.sertId;
				if(null!=sertId && !"".equals(sertId)){
					stsMap.put("seatUserId", sertId);
					PiccUser piccUser1 = piccUserService.getUserInfo(sertId,token);
					stsMap.put("seatUserName", piccUser1.userName);
				}else{
					stsMap.put("seatUserId", "");
					stsMap.put("seatUserName","");
				}
				stsMap.put("lon", piccTaskPool.lon);
				stsMap.put("lat", piccTaskPool.lat);
				stsMap.put("address", piccTaskPool.address);
				stsMap.put("taskMoney", piccTaskPool.caseMoney == null ? " " : piccTaskPool.caseMoney);
				stsMap.put("taskDescribe", piccTaskPool.taskDescribe == null ? " " : piccTaskPool.taskDescribe);
				stsMap.put("dsNumber", piccTaskPool.dsNumber == null ? " " : piccTaskPool.dsNumber);
				stsMap.put("zbDesc", piccTaskPool.taskZbInfo == null ? " " : piccTaskPool.taskZbInfo);
				List<PiccTaskFile> piccTaskFileList = piccTaskFileService.findImg(piccTaskPool.caseNumber,
						piccTaskPool.carNumber);
				List imgs = new ArrayList();
				if (piccTaskFileList!=null && piccTaskFileList.size()> 0 ) {
					for (int i = 0; i < piccTaskFileList.size(); i++) {
						String fileUrl = piccTaskFileList.get(i).fileUrl;
						String replace = fileUrl.replace("\\", "%2f").replace("/", "%2f");
						String s = scFileSavePath + replace;
						imgs.add(s);
					}
					stsMap.put("imageList", imgs);
				} else {
					stsMap.put("imageList", imgs);
				}
				List<PiccTaskAudio> piccTaskAudioList = piccTaskAudioService.findAudioByTaskId(piccTaskPool.taskId);
				if (piccTaskAudioList!=null && piccTaskAudioList.size()>0 ) {
					String fileUrl = piccTaskAudioList.get(0).audioUrl;
					String replace = fileUrl.replace("\\", "%2f").replace("/", "%2f");
					String s = scFileSavePath + replace;
					stsMap.put("caseAudio", s);
				} else {
					stsMap.put("caseAudio", " ");
				}
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

		return null;
	}

	// 获取本组坐席列表接口（弃用）
	@Execute(validator = false)
	public String seatUserList() {

		Gson gson = new Gson();
		StringBuffer indata = StreamUtil.getRequestBody(req);
		Map stsMap = new HashMap<String, String>();

		Map<String, String> mapData = gson.fromJson(indata.toString(), Map.class);
		if (mapData == null)
			return null;

		String groupName = (String) mapData.get("groupName");

		try {
			rep.setCharacterEncoding("utf-8");
			if (StringUtils.isBlank(groupName)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "groupName不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}

			String userType1 = Constants.USER_TYPE_SEAT;
			String userType2 = Constants.USER_TYPE_LEADER;
			List<PiccUser> piccUser = piccUserService.findByGroupName(groupName, userType1, userType2);
			if (null != piccUser && piccUser.size() > 0) {
				stsMap.put("sts", "0");
				List list = new ArrayList();
				for (int i = 0; i < piccUser.size(); i++) {
					Map a = new HashMap();
					a.put("seatUserId", piccUser.get(i).userId);
					a.put("seatUserName", piccUser.get(i).userName);
					a.put("userType", piccUser.get(i).userType);
					list.add(a);
				}
				stsMap.put("seatUserList", list);
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			} else {
				stsMap.put("sts", "2");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

		return null;
	}

	// 排队案件接口
	@Execute(validator = false)
	public String queueCaseList() {

		Gson gson = new Gson();
		StringBuffer indata = StreamUtil.getRequestBody(req);
		Map stsMap = new HashMap<String, String>();

		Map<String, String> mapData = gson.fromJson(indata.toString(), Map.class);
		if (mapData == null)
			return null;
		if (BaseAction.checkToken(indata, rep) == false)
			return null; // 验证token是否有效 无效直接返回错误码-1000

		String groupName = (String) mapData.get("groupName");
		String searchKey = (String) mapData.get("searchKey");
		String pageNum = (String) mapData.get("pageNum");
		String pageCount = (String) mapData.get("pageCount");
		String token = (String) mapData.get("token");
		try {
			rep.setCharacterEncoding("utf-8");
			if (StringUtils.isBlank(groupName)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "groupName不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			if (StringUtils.isBlank(token)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "token不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			if(pageNum==null)  pageNum = "1";
			if(pageCount==null) pageCount = "10000";
			int pageCountt = Integer.parseInt(pageCount);
			int startt = (Integer.parseInt(pageNum) - 1) * pageCountt;
			String taskStatus=Constants.TASK_STATUS_DAICL;
			String number0=Constants.TASK_DEFAULT_NUMBER;
			String number1=Constants.TASK_FIRST_NUMBER;
			String number2=Constants.TASK_SECOND_NUMBER;
			//List<PiccTaskPool> piccTaskPool = piccTaskPoolService.findPaiduiTask(groupName, searchKey);
			List<PiccTaskPool> piccTaskPool = piccTaskPoolService.findPaiduiTaskk(groupName,taskStatus,searchKey,number0,number1,number2,startt,pageCountt);
			if (null != piccTaskPool && piccTaskPool.size() > 0) {
				int totalCount = piccTaskPoolService.findPaiduiTaskkCount(groupName,taskStatus,searchKey,number0,number1,number2);
				if (totalCount % pageCountt == 0) {
					stsMap.put("sumPage", totalCount / pageCountt);
				} else {
					stsMap.put("sumPage", totalCount / pageCountt + 1);
				}
				stsMap.put("totalCount", totalCount);
				stsMap.put("sts", "0");
				List list = new ArrayList();
				for (int i = 0; i < piccTaskPool.size(); i++) {
					Map a = new HashMap();
					a.put("caseNumber", piccTaskPool.get(i).caseNumber);
					a.put("carNumber", piccTaskPool.get(i).carNumber);
					a.put("caseType", piccTaskPool.get(i).caseType);
					a.put("dsType", piccTaskPool.get(i).taskType);
					String leadingUserId = piccTaskPool.get(i).leadingUserId;
					PiccUser piccUser = piccUserService.getUserInfo(leadingUserId, token);
					a.put("userId", leadingUserId);
					a.put("userName", piccUser.userName);
					a.put("userCompany", piccUser.userCompany);
					a.put("taskId", piccTaskPool.get(i).taskId);
					a.put("sertId", piccTaskPool.get(i).sertId);
					DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
					a.put("createTime", sdf.format(piccTaskPool.get(i).createTime));
					list.add(a);
				}
				stsMap.put("seatUserList", list);
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			} else {
				stsMap.put("sts", "2");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

		return null;
	}

	// 我的案件接口
	@Execute(validator = false)
	public String myCaseList() {

		Gson gson = new Gson();
		StringBuffer indata = StreamUtil.getRequestBody(req);
		Map stsMap = new HashMap<String, String>();

		Map<String, String> mapData = gson.fromJson(indata.toString(), Map.class);
		if (mapData == null)
			return null;
		if (BaseAction.checkToken(indata, rep) == false)
			return null; // 验证token是否有效 无效直接返回错误码-1000

		String seatUserId = (String) mapData.get("seatUserId");
		String searchKey = (String) mapData.get("searchKey");
		String pageNum = (String) mapData.get("pageNum");
		String pageCount = (String) mapData.get("pageCount");
		String token = (String) mapData.get("token");
		try {
			rep.setCharacterEncoding("utf-8");
			if (StringUtils.isBlank(token)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "token不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			if (StringUtils.isBlank(seatUserId)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "seatUserId不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			if(pageNum==null)  pageNum = "1";
			if(pageCount==null) pageCount = "10000";
			int pageCountt = Integer.parseInt(pageCount);
			int startt = (Integer.parseInt(pageNum) - 1) * pageCountt;
			/*列表展示优先级:
			 		  1.正在处理的案件
					  2.断线重连的案件
					  3.组长指定的案件
					  4.已完成的案件
			*/
			String taskStatus1 = Constants.TASK_STATUS_WAIT_APP;
			String firstNumber=	Constants.TASK_SECOND_NUMBER;
			String taskStatus2 = Constants.TASK_STATUS_DAICL; 
			String taskStatus3 = Constants.TASK_STATUS_YICL; 
			List<PiccTaskPool> piccTaskPool = piccTaskPoolService.findBySeatId(seatUserId, taskStatus1,firstNumber, taskStatus2,taskStatus3,searchKey,startt,pageCountt);
			if (null != piccTaskPool && piccTaskPool.size() > 0) {
				int totalCount = piccTaskPoolService.findBySeatIdCount(seatUserId, taskStatus1,firstNumber, taskStatus2,taskStatus3,searchKey);
				if (totalCount % pageCountt == 0) {
					stsMap.put("sumPage", totalCount / pageCountt);
				} else {
					stsMap.put("sumPage", totalCount / pageCountt + 1);
				}
				stsMap.put("totalCount", totalCount);
				stsMap.put("sts", "0");
				List list = new ArrayList();
				for (int i = 0; i < piccTaskPool.size(); i++) {
					Map a = new HashMap();
					a.put("caseNumber", piccTaskPool.get(i).caseNumber);
					a.put("carNumber", piccTaskPool.get(i).carNumber);
					a.put("caseType", piccTaskPool.get(i).caseType);
					a.put("dsType", piccTaskPool.get(i).taskType);
					String leadingUserId = piccTaskPool.get(i).leadingUserId;
					PiccUser piccUser = piccUserService.getUserInfo(leadingUserId, token);
					a.put("userId", leadingUserId);
					a.put("userName", piccUser.userName);
					a.put("userCompany", piccUser.userCompany);
					a.put("caseStatus", piccTaskPool.get(i).taskStatus);
					a.put("taskId", piccTaskPool.get(i).taskId);
					a.put("taskMoney", piccTaskPool.get(i).caseMoney == null ? " " : piccTaskPool.get(i).caseMoney);
					DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
					a.put("createTime", sdf.format(piccTaskPool.get(i).createTime));
					list.add(a);
				}
				stsMap.put("caseList", list);
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			} else {
				stsMap.put("sts", "2");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

		return null;
	}

	// 待处理案件案件接口
	@Execute(validator = false)
	public String todoCaseList() {

		Gson gson = new Gson();
		StringBuffer indata = StreamUtil.getRequestBody(req);
		Map stsMap = new HashMap<String, String>();

		Map<String, String> mapData = gson.fromJson(indata.toString(), Map.class);
		if (mapData == null)
			return null;
		if (BaseAction.checkToken(indata, rep) == false)
			return null; // 验证token是否有效 无效直接返回错误码-1000

		String seatUserId = (String) mapData.get("seatUserId");
		String searchKey = (String) mapData.get("searchKey");
		String pageNum = (String) mapData.get("pageNum");
		String pageCount = (String) mapData.get("pageCount");
		String token = (String) mapData.get("token");
		try {
			rep.setCharacterEncoding("utf-8");
			if (StringUtils.isBlank(seatUserId)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "seatUserId不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
		

			if(pageNum==null)  pageNum = "1";
			if(pageCount==null) pageCount = "10000";
			int pageCountt = Integer.parseInt(pageCount);
			int startt = (Integer.parseInt(pageNum) - 1) * pageCountt;
			String taskStatus = Constants.TASK_STATUS_YAOQZB;

			List<PiccTaskPool> piccTaskPool = piccTaskPoolService.findBySeatIdd(seatUserId, taskStatus, searchKey,startt,pageCountt);
			if (null != piccTaskPool && piccTaskPool.size() > 0) {
				int totalCount = piccTaskPoolService.findBySeatIddCount(seatUserId, taskStatus, searchKey);
				if (totalCount % pageCountt == 0) {
					stsMap.put("sumPage", totalCount / pageCountt);
				} else {
					stsMap.put("sumPage", totalCount / pageCountt + 1);
				}
				stsMap.put("totalCount", totalCount);
				stsMap.put("sts", "0");
				List list = new ArrayList();
				for (int i = 0; i < piccTaskPool.size(); i++) {
					Map a = new HashMap();
					a.put("caseNumber", piccTaskPool.get(i).caseNumber);
					a.put("carNumber", piccTaskPool.get(i).carNumber);
					a.put("caseType", piccTaskPool.get(i).caseType);
					a.put("dsType", piccTaskPool.get(i).taskType);
					String leadingUserId = piccTaskPool.get(i).leadingUserId;
					PiccUser piccUser = piccUserService.getUserInfo(leadingUserId, token);
					a.put("userId", leadingUserId);
					a.put("userName", piccUser.userName);
					a.put("userCompany", piccUser.userCompany);
					a.put("caseStatus", "增补");
					a.put("taskId", piccTaskPool.get(i).taskId);
					DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
					a.put("createTime", sdf.format(piccTaskPool.get(i).createTime));
					list.add(a);
				}
				stsMap.put("caseList", list);
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			} else {
				stsMap.put("sts", "2");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

		return null;
	}

	/**
	 * 获取任务相关图片压缩包
	 * @author 尹键
	 * @return
	 */
	@Execute(validator = false)
	public String fetchCaseImageZip() {
		// 从请求报文中获取任务id
		Gson gson = new Gson();
		StringBuffer indata = StreamUtil.getRequestBody(req);
		Map stsMap = new HashMap<String, String>();
		Map<String, String> mapData = gson.fromJson(indata.toString(), Map.class);
		// 获取工作目录
		ServletContext context = req.getSession().getServletContext();
		final String scFileSavePath = context.getInitParameter("PHOTO_STORE_PATH");
			if (scFileSavePath == null) {
				// 环境变量未配置，异常退出
				System.out.println("环境变量[PHOTO_STORE_PATH]未配置，异常退出");
				return null;
			}
		if (mapData == null)
			return null;
		String taskId = (String) mapData.get("taskId");
		String token = (String) mapData.get("token");
		try {
			
			if (StringUtils.isBlank(taskId)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "taskId不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}

		PiccTaskPool piccTaskPool = piccTaskPoolService.findById(taskId);
		if(null!=piccTaskPool){

			// 根据任务id获取图片文件列表
			List<String> fileList = piccTaskFileService.findImagesByTaskId(taskId);
			if ( fileList!=null && fileList.size()> 0) {
				for (int i = 0; i < fileList.size(); i++) {
					//fileList.set(i, scFileSavePath + File.separator + fileList.get(i));
					fileList.set(i, scFileSavePath + fileList.get(i));
				}
				
				// 将所有图片压缩成zip包
				String srcFileDir = scFileSavePath + "tmp/" + taskId;
				String targetFileDir = scFileSavePath + "tmp";
				String zipFileName = taskId + ".zip";
					// 初始化临时目录
					File dir = new File(srcFileDir);
					if (dir.exists()) {
						File[] tmp = dir.listFiles();
						for (int i = 0; i < tmp.length; i++) {
							tmp[i].delete();
						}
					} else {
						dir.mkdirs();
					}
					File zipFile = new File(targetFileDir + File.separator + zipFileName);
					if (zipFile.exists()) {
						zipFile.delete();
					}
					// 将图片文件拷贝至临时目录
					for (int i = 0; i < fileList.size(); i++) {
						//String tmpName[] = fileList.get(i).split(File.separator);
						String tmpName[] = fileList.get(i).split(File.separator+File.separator);

						copyFile(fileList.get(i), srcFileDir + File.separator + tmpName[tmpName.length - 1]);
					}
					// 压缩文件到zip包
					try {
						ZipUtil.zip(srcFileDir, targetFileDir, zipFileName);
					} catch (Exception e) {
						e.printStackTrace();
					}

				
				// 将zip包以流的形式返回给请求侧
					FileInputStream in = new FileInputStream(targetFileDir + File.separator + zipFileName);
					ResponseUtil.download(zipFileName, in);
				
			} else {
				stsMap.put("sts", "2");
				stsMap.put("msg", "该案件没有图片");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			}
		
		}else{
			stsMap.put("sts", "2");
			stsMap.put("msg", "没有该案件");
			rep.getWriter().println(gson.toJson(stsMap));
			rep.getWriter().flush();
		}
		}catch (IOException e) {
			e.printStackTrace();
		}
		
		return null;
	}

	// 复制文件
	private void copyFile(String src, String dest) throws IOException {
		FileInputStream in = new FileInputStream(src);
		File file = new File(dest);
		if (!file.exists())
			file.createNewFile();
		FileOutputStream out = new FileOutputStream(file);
		int c;
		byte buffer[] = new byte[1024];
		while ((c = in.read(buffer)) != -1) {
			for (int i = 0; i < c; i++)
				out.write(buffer[i]);
		}
		in.close();
		out.close();
	}

	/**
	 * 坐席组长指定案件处理坐席接口
	 * @author 尹键
	 * @return
	 */
	@Execute(validator = false)
	public String dispatchTaskSeat() {

		Gson gson = new Gson();
		StringBuffer indata = StreamUtil.getRequestBody(req);
		Map<String, String> stsMap = new HashMap<String, String>();

		Map<String, String> mapData = gson.fromJson(indata.toString(), Map.class);
		if (mapData == null)
			return null;
		if (BaseAction.checkToken(indata, rep) == false)
			return null; // 验证token是否有效 无效直接返回错误码-1000

		String taskId = (String) mapData.get("taskId");
		String seatUserId = (String) mapData.get("seatUserId");
		String token = (String) mapData.get("token");
		try {
			rep.setCharacterEncoding("utf-8");
			if (StringUtils.isBlank(taskId)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "未指定任务id");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			if (StringUtils.isBlank(seatUserId)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "未指定坐席id");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}

			PiccTaskPool piccTaskPool = piccTaskPoolService.findById(taskId);
			if (null == piccTaskPool) {
				stsMap.put("sts", "2");
				stsMap.put("msg", "任务id不存在");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			} else {
				if (!"0".equals(piccTaskPool.taskStatus)) {
					stsMap.put("sts", "2");
					stsMap.put("msg", "待处理队列中已无此案件任务");
					rep.getWriter().println(gson.toJson(stsMap));
					rep.getWriter().flush();
				}
				piccTaskPool.sertId = seatUserId;
				piccTaskPool.updateTime=dbTimeService.getDbTimeStamp();
				piccTaskPoolService.update(piccTaskPool);
				stsMap.put("sts", "0");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

		return null;
	}

	/**
	 * 更新案件状态接口
	 * @return
	 */
	@Execute(validator = false)
	public String updateCaseStatus() {

		Gson gson = new Gson();
		StringBuffer indata = StreamUtil.getRequestBody(req);
		Map<String, String> stsMap = new HashMap<String, String>();

		Map<String, String> mapData = gson.fromJson(indata.toString(), Map.class);
		if (mapData == null)
			return null;
		if (BaseAction.checkToken(indata, rep) == false)
			return null; // 验证token是否有效 无效直接返回错误码-1000

		String taskId = (String) mapData.get("taskId");
		String taskStatus = (String) mapData.get("caseStatus");
		String token = (String) mapData.get("token");
		try {
			rep.setCharacterEncoding("utf-8");
			if (StringUtils.isBlank(taskId)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "taskId不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			if (StringUtils.isBlank(taskStatus)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "caseStatus不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}

			PiccTaskPool piccTaskPool = piccTaskPoolService.findById(taskId);
			if (null == piccTaskPool) {
				stsMap.put("sts", "2");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			} else {
				Timestamp dbTimeStamp = dbTimeService.getDbTimeStamp();
				piccTaskPool.taskStatus = taskStatus;
				piccTaskPool.updateTime = dbTimeStamp;
				piccTaskPoolService.update(piccTaskPool);
				PiccTaskStatus piccTaskStatus = new PiccTaskStatus();
				piccTaskStatus.id = UUID.randomUUID().toString().replace("-", "");
				piccTaskStatus.taskId = taskId;
				piccTaskStatus.taskStatus = taskStatus;
				piccTaskStatus.taskType=piccTaskPool.taskType;
				piccTaskStatus.createTime = dbTimeStamp;
				piccTaskStatusService.insert(piccTaskStatus);
				stsMap.put("sts", "0");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

		return null;
	}

	/**
	 * 案件定损类型转换
	 * @author 尹键
	 * @return
	 */
	@Execute(validator = false)
	public String updateDsType() {

		Gson gson = new Gson();
		StringBuffer indata = StreamUtil.getRequestBody(req);
		Map<String, String> stsMap = new HashMap<String, String>();

		Map<String, String> mapData = gson.fromJson(indata.toString(), Map.class);
		if (mapData == null)
			return null;
		if (BaseAction.checkToken(indata, rep) == false)
			return null; // 验证token是否有效 无效直接返回错误码-1000

		String taskId = (String) mapData.get("taskId");
		String dsType = (String) mapData.get("dsType");
		String token = (String) mapData.get("token");
		try {
			rep.setCharacterEncoding("utf-8");
			if (StringUtils.isBlank(taskId)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "未指定任务id");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			if (StringUtils.isBlank(dsType)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "未指定定损类型");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			
			// 更新案件任务表中的数据
			PiccTaskPool piccTaskPool = piccTaskPoolService.findById(taskId);
			if (null == piccTaskPool) {
				stsMap.put("sts", "2");
				stsMap.put("msg", "指定案件任务不存在");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			} else {
				Timestamp dbTimeStamp = dbTimeService.getDbTimeStamp();
				piccTaskPool.taskType = dsType;
				piccTaskPool.updateTime = dbTimeStamp;
				piccTaskPoolService.update(piccTaskPool);
				// 添加数据到任务状态表
				PiccTaskStatus piccTaskStatus = new PiccTaskStatus();
				piccTaskStatus.id = UUID.randomUUID().toString().replace("-", "");
				piccTaskStatus.taskId = taskId;
				piccTaskStatus.taskStatus = piccTaskPool.taskStatus;
				piccTaskStatus.taskType = dsType;
				piccTaskStatus.createTime = dbTimeStamp;
				piccTaskStatusService.insert(piccTaskStatus);
				stsMap.put("sts", "0");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

		return null;
	}

	//取消待处理案件案件接口
	@Execute(validator = false)
	public String delCase() {

		Gson gson = new Gson();
		StringBuffer indata = StreamUtil.getRequestBody(req);
		Map stsMap = new HashMap<String, String>();

		Map<String, String> mapData = gson.fromJson(indata.toString(), Map.class);
		if (mapData == null)
			return null;
		if (BaseAction.checkToken(indata, rep) == false)
			return null; // 验证token是否有效 无效直接返回错误码-1000

		String taskId = (String) mapData.get("taskId");
		String token = (String) mapData.get("token");
		try {
			rep.setCharacterEncoding("utf-8");
			if (StringUtils.isBlank(taskId)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "taskId不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}

			//String taskStatus = Constants.TASK_STATUS_DAICL;

			//PiccTaskPool piccTaskPool = piccTaskPoolService.findDaiclById(taskId,taskStatus);
			PiccTaskPool piccTaskPool = piccTaskPoolService.findById(taskId);
			if (null != piccTaskPool) {
				piccTaskPoolService.delete(piccTaskPool);
				piccTaskStatusService.deleteTask(taskId);
				stsMap.put("sts", "0");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			} else {
				stsMap.put("sts", "2");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

		return null;
	}
	
	//设置案件优先处理接口
	@Execute(validator = false)
	public String configCaseOrder() {
		Gson gson = new Gson();
		StringBuffer indata = StreamUtil.getRequestBody(req);
		Map stsMap = new HashMap<String, String>();

		Map<String, String> mapData = gson.fromJson(indata.toString(), Map.class);
		if (mapData == null)
			return null;
		if (BaseAction.checkToken(indata, rep) == false)
			return null; // 验证token是否有效 无效直接返回错误码-1000

		String taskId = (String) mapData.get("taskId");
		String token = (String) mapData.get("token");
		try {
			rep.setCharacterEncoding("utf-8");
			if (StringUtils.isBlank(taskId)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "taskId不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}

			PiccTaskPool piccTaskPool = piccTaskPoolService.findById(taskId);
			if (null != piccTaskPool) {
				//将案件设为优先处理
				piccTaskPool.firstNumber=Integer.valueOf(Constants.TASK_FIRST_NUMBER);
				piccTaskPool.updateTime=dbTimeService.getDbTimeStamp();
				piccTaskPoolService.update(piccTaskPool);
				stsMap.put("sts", "0");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			} else {
				stsMap.put("sts", "2");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

		return null;
	}
	
	//坐席获取下一个案件接口
	@Execute(validator = false)
	public String nextCase() {
	
		Gson gson = new Gson();
		StringBuffer indata = StreamUtil.getRequestBody(req);
		Map stsMap = new HashMap<String, String>();

		Map<String, String> mapData = gson.fromJson(indata.toString(), Map.class);
		if (mapData == null)
			return null;
		if (BaseAction.checkToken(indata, rep) == false)
			return null; // 验证token是否有效 无效直接返回错误码-1000

		String sertId = (String) mapData.get("seatUserId");
		String groupName = (String) mapData.get("group");
		String token = (String) mapData.get("token");
		try {
			rep.setCharacterEncoding("utf-8");
			if (StringUtils.isBlank(sertId)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "seatUserId不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			if (StringUtils.isBlank(groupName)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "group不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}

			/*
			     查询该坐席上次成功获取案件的时间
			*/
			PiccLatestTaskTime piccLatestTaskTime = piccLatestTaskTimeService.findById(sertId);
			Timestamp dbTimeStamp = dbTimeService.getDbTimeStamp();
			
			if(piccLatestTaskTime!=null){
				Timestamp acTime = piccLatestTaskTime.acTime;
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				String acTime1 = sdf.format(acTime);
				String dbTimeStamp1 = sdf.format(dbTimeStamp);
				Date acTime2 = sdf.parse(acTime1);
				Date dbTimeStamp2 = sdf.parse(dbTimeStamp1);
				long min=(dbTimeStamp2.getTime()-acTime2.getTime())/1000;
				
				//此次获取任务时间距上次成功获取任务时间不超过60S,不允许再次获取任务
				if(min<=Long.valueOf(Constants.SUCCESS_TASK_TIME)){
					stsMap.put("sts", "3");
					rep.getWriter().println(gson.toJson(stsMap));
					rep.getWriter().flush();
					return null;
				}
			}
			
			/*
			if(piccLatestTaskTime==null){
				piccLatestTaskTime = new PiccLatestTaskTime();
				piccLatestTaskTime.seatId=sertId;
				piccLatestTaskTime.acTime=dbTimeStamp;
				piccLatestTaskTimeService.insert(piccLatestTaskTime);
			}else{
				Timestamp acTime = piccLatestTaskTime.acTime;
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				String acTime1 = sdf.format(acTime);
				String dbTimeStamp1 = sdf.format(dbTimeStamp);
				Date acTime2 = sdf.parse(acTime1);
				Date dbTimeStamp2 = sdf.parse(dbTimeStamp1);
				long min=(dbTimeStamp2.getTime()-acTime2.getTime())/1000;
				System.out.println(min);
				//此次获取任务时间距上次成功获取任务时间不超过60S,不允许再次获取任务
				if(min<=Long.valueOf(Constants.SUCCESS_TASK_TIME)){
					stsMap.put("sts", "3");
					rep.getWriter().println(gson.toJson(stsMap));
					rep.getWriter().flush();
					return null;
				}
			}
			*/
			
			String taskStatus=Constants.TASK_STATUS_DAICL;
			String taskType=Constants.TASK_TYPE_VIDEO;
			String number0=Constants.TASK_DEFAULT_NUMBER;
			String number1=Constants.TASK_FIRST_NUMBER;
			String number2=	Constants.TASK_SECOND_NUMBER;
			/*获取案件的优先级:
	 		  1.置顶的案件
			  2.断线重连的案件
			  3.组长指定的案件
			  4.普通的案件
			*/
			List<PiccTaskPool> findPaiduiTaskkk = piccTaskPoolService.findPaiduiTaskkk(groupName,sertId,taskStatus,taskType,number0, number1,number2);
			if (null!=findPaiduiTaskkk && findPaiduiTaskkk.size()>0) {
				PiccTaskPool piccTaskPool =null;
				for (int i = 0; i < findPaiduiTaskkk.size(); i++) {
					piccTaskPool = findPaiduiTaskkk.get(i);
					piccTaskPool.sertId=sertId;
					piccTaskPool.taskStatus=Constants.TASK_STATUS_WAIT_APP;
					int j = piccTaskPoolService.updateSertIdd(piccTaskPool);
					if(j==1){
						Timestamp dbTimeStamp2 = dbTimeService.getDbTimeStamp();
						piccTaskPool.updateTime=dbTimeStamp2;
						piccTaskPoolService.update(piccTaskPool);
						PiccTaskStatus piccTaskStatus = new PiccTaskStatus();
						piccTaskStatus.id = UUID.randomUUID().toString().replace("-", "");
						piccTaskStatus.taskId = piccTaskPool.taskId;
						piccTaskStatus.taskType = piccTaskPool.taskType;
						piccTaskStatus.taskStatus = Constants.TASK_STATUS_WAIT_APP;
						piccTaskStatus.createTime = dbTimeStamp;
						piccTaskStatusService.insert(piccTaskStatus);
						
						//修改成功获取案件的时间
						piccLatestTaskTime = piccLatestTaskTimeService.findById(sertId);
						if(piccLatestTaskTime == null){
							piccLatestTaskTime = new PiccLatestTaskTime();
							piccLatestTaskTime.seatId=sertId;
							piccLatestTaskTime.acTime=dbTimeStamp;
							piccLatestTaskTimeService.insert(piccLatestTaskTime);
						} else {
							piccLatestTaskTime.acTime=dbTimeStamp2;
							piccLatestTaskTimeService.update(piccLatestTaskTime);
						}
						
						PiccUser piccUser = piccUserService.getUserInfo(piccTaskPool.leadingUserId, token);
						stsMap.put("sts", "0");
						stsMap.put("taskId",piccTaskPool.taskId);
						stsMap.put("userId",piccTaskPool.leadingUserId);
						stsMap.put("userName",piccUser.userName);
						rep.getWriter().println(gson.toJson(stsMap));
						rep.getWriter().flush();
						return null;
					}
				}
			} else {
				stsMap.put("sts", "2");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			}
		} catch (IOException e) {
			e.printStackTrace();
		} catch (ParseException e) {
			e.printStackTrace();
		}

		return null;
	}
	
	//退回案件接口
	@Execute(validator = false)
	public String returnCase() {

		Gson gson = new Gson();
		StringBuffer indata = StreamUtil.getRequestBody(req);
		Map stsMap = new HashMap<String, String>();

		Map<String, String> mapData = gson.fromJson(indata.toString(), Map.class);
		if (mapData == null)
			return null;
		if (BaseAction.checkToken(indata, rep) == false)
			return null; // 验证token是否有效 无效直接返回错误码-1000

		String taskId = (String) mapData.get("taskId");
		String token = (String) mapData.get("token");
		try {
			rep.setCharacterEncoding("utf-8");
			if (StringUtils.isBlank(taskId)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "taskId不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			PiccTaskPool piccTaskPool = piccTaskPoolService.findById(taskId);
			if (null!=piccTaskPool ) {
				Timestamp dbTimeStamp = dbTimeService.getDbTimeStamp();
				piccTaskPool.taskStatus=Constants.TASK_STATUS_DAICL;
				piccTaskPool.updateTime= dbTimeStamp;
				piccTaskPoolService.deleteSertId(piccTaskPool);
				
				PiccTaskStatus piccTaskStatus = new PiccTaskStatus();
				piccTaskStatus.id = UUID.randomUUID().toString().replace("-", "");
				piccTaskStatus.taskId = taskId;
				piccTaskStatus.taskType = piccTaskPool.taskType;
				piccTaskStatus.taskStatus = Constants.TASK_STATUS_DAICL;
				piccTaskStatus.createTime = dbTimeStamp;
				piccTaskStatusService.insert(piccTaskStatus);
				stsMap.put("sts", "0");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			} else {
				stsMap.put("sts", "2");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

		return null;
	}
	
	//案件状态批量更新接口
	@Execute(validator = false)
	public String multiCaseUpdate() {

		Gson gson = new Gson();
		StringBuffer indata = StreamUtil.getRequestBody(req);
		Map stsMap = new HashMap<String, String>();

		Map mapData = gson.fromJson(indata.toString(), Map.class);
		if (mapData == null)
			return null;
		if (BaseAction.checkToken(indata, rep) == false)
			return null; // 验证token是否有效 无效直接返回错误码-1000

		List<Map> caseLists = (List) mapData.get("caseList");
		String token = (String) mapData.get("token");
		try {
			rep.setCharacterEncoding("utf-8");
			List errorList = new ArrayList();
			for (Map caseList : caseLists) {
				String taskId = (String) caseList.get("taskId");
				String caseStatus = (String) caseList.get("caseStatus");
				if (StringUtils.isBlank(taskId)) {
					stsMap.put("sts", "2");
					stsMap.put("msg", "taskId不能为空");
					rep.getWriter().println(gson.toJson(stsMap));
					rep.getWriter().flush();
					return null;
				}
				if (StringUtils.isBlank(caseStatus)) {
					stsMap.put("sts", "2");
					stsMap.put("msg", "caseStatus不能为空");
					rep.getWriter().println(gson.toJson(stsMap));
					rep.getWriter().flush();
					return null;
				}
				PiccTaskPool piccTaskPool = piccTaskPoolService.findById(taskId);
				if (null!=piccTaskPool) {
					Timestamp dbTimeStamp = dbTimeService.getDbTimeStamp();
					piccTaskPool.taskStatus=caseStatus;
					piccTaskPool.updateTime= dbTimeStamp;
					piccTaskPoolService.update(piccTaskPool);
					PiccTaskStatus piccTaskStatus = new PiccTaskStatus();
					piccTaskStatus.id = UUID.randomUUID().toString().replace("-", "");
					piccTaskStatus.taskId = taskId;
					piccTaskStatus.taskType = piccTaskPool.taskType;
					piccTaskStatus.taskStatus = caseStatus;
					piccTaskStatus.createTime = dbTimeStamp;
					piccTaskStatusService.insert(piccTaskStatus);
				} else {
					Map errorMap = new HashMap<String, String>();
					errorMap.put("taskId", taskId);
					errorList.add(errorMap);
				}
			}
			if(errorList.size()>0){
				stsMap.put("sts", "1");
				stsMap.put("caseList", errorList);
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			}else{
				stsMap.put("sts", "0");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}

		return null;
	}
	
	//获取指定用户未完成案件列表接口
	@Execute(validator = false)
	public String fetchNgCaseList() {
		Gson gson = new Gson();
		StringBuffer indata = StreamUtil.getRequestBody(req);
		Map stsMap = new HashMap<String, String>();

		Map<String, String> mapData = gson.fromJson(indata.toString(), Map.class);
		if (mapData == null)
			return null;
		if (BaseAction.checkToken(indata, rep) == false)
			return null; // 验证token是否有效 无效直接返回错误码-1000

		String userId = (String) mapData.get("userId");
		String pageNum = (String) mapData.get("pageNum");
		String pageCount = (String) mapData.get("pageCount");
		String token = (String) mapData.get("token");
		try {
			rep.setCharacterEncoding("utf-8");
			if (StringUtils.isBlank(userId)) {
				stsMap.put("sts", "2");
				stsMap.put("msg", "userId不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			if (StringUtils.isBlank(pageNum)) {
				stsMap.put("sts", "2");
				stsMap.put("msg", "pageNum不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			if (StringUtils.isBlank(pageCount)) {
				stsMap.put("sts", "2");
				stsMap.put("msg", "pageCount不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			int pageCount1 = Integer.parseInt(pageCount);
			int start = (Integer.parseInt(pageNum) - 1) * pageCount1;
			String taskStatus = Constants.TASK_STATUS_YICAJ;
			String searchKey=null;
			List<PiccTaskPool> PiccTaskPoolList = piccTaskPoolService.findByUserId(userId, taskStatus, searchKey, start,
					pageCount1);
			if (null != PiccTaskPoolList && PiccTaskPoolList.size() > 0) {
				int totalCount = piccTaskPoolService.findTotalCount(userId, taskStatus, searchKey);
				if (totalCount % pageCount1 == 0) {
					stsMap.put("sumPage", totalCount / pageCount1);
				} else {
					stsMap.put("sumPage", totalCount / pageCount1 + 1);
				}
				stsMap.put("totalCount", totalCount);
				stsMap.put("sts", "0");
				List list = new ArrayList();
				for (int i = 0; i < PiccTaskPoolList.size(); i++) {
					Map a = new HashMap();
					DateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
					a.put("taskId", PiccTaskPoolList.get(i).taskId);
					a.put("caseNum", PiccTaskPoolList.get(i).caseNumber);
					a.put("carNumber", PiccTaskPoolList.get(i).carNumber);
					String sertId = PiccTaskPoolList.get(i).sertId;
					if(null!=sertId && !"".equals(sertId)){
						a.put("seatUserId", sertId);
						PiccUser piccUser1 = piccUserService.getUserInfo(sertId, token);
						a.put("seatUserName", piccUser1.userName);
					}else{
						a.put("seatUserId", "");
						a.put("seatUserName","");
					}
					a.put("caseType", PiccTaskPoolList.get(i).caseType);
					a.put("dsType", PiccTaskPoolList.get(i).taskType);
					a.put("updateTime", sdf.format(PiccTaskPoolList.get(i).updateTime));
					list.add(a);
				}
				stsMap.put("caseList", list);
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			} else {
				stsMap.put("sts", "1");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			}

		} catch (IOException e) {
			e.printStackTrace();
		}

		return null;
	}
	
	//断线视频案件续连接口
	@Execute(validator = false)
	public String reconnectCase() {
		Gson gson = new Gson();
		StringBuffer indata = StreamUtil.getRequestBody(req);
		Map stsMap = new HashMap<String, String>();

		Map<String, String> mapData = gson.fromJson(indata.toString(), Map.class);
		if (mapData == null)
			return null;
		if (BaseAction.checkToken(indata, rep) == false)
			return null; // 验证token是否有效 无效直接返回错误码-1000

		String taskId = (String) mapData.get("taskId");
		String userId = (String) mapData.get("userId");
		String token = (String) mapData.get("token");
	
		try {
			rep.setCharacterEncoding("utf-8");
			if (StringUtils.isBlank(userId)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "userId不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			if (StringUtils.isBlank(taskId)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "taskId不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			if (StringUtils.isBlank(token)) {
				stsMap.put("sts", "1");
				stsMap.put("msg", "token不能为空");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
				return null;
			}
			String taskStatus = Constants.TASK_STATUS_YICAJ;
			PiccTaskPool piccTaskPool = piccTaskPoolService.findByTaskIdUserId(taskId,userId, taskStatus);
			if (null != piccTaskPool) {
//				PiccUser user = piccUserService.findById(userId);
//				String firstSectorName = user.firstSectorName;
//				String secondSectorName = user.secondSectorName;
//				String thirdSectorName = user.thirdSectorName;
//				String groupName = user.groupName;
//				String isOnline = Constants.USER_STATUS_ONLINE;
//				String userType1 = Constants.USER_TYPE_SEAT;
//				String userType2 = Constants.USER_TYPE_LEADER;
				//判断该组有没有人在线
//				int totalCount=piccUserService.findIsOnlineCount(firstSectorName,secondSectorName,thirdSectorName,
//							groupName,isOnline,userType1,userType2);
//				
		
				int totalCount = piccUserOnlineStatusService.findIsOnlineCount(userId, token);
				if(totalCount>0){
					Timestamp dbTimeStamp = dbTimeService.getDbTimeStamp();
					PiccUser piccUser = piccUserService.getUserInfo(piccTaskPool.sertId, token);
					//判断处理该案件的坐席是否在线  在线分给该坐席,不在线分给其他坐席
					if(null!=piccUser && Constants.USER_STATUS_ONLINE.equals(piccUser.isOnline)){
						piccTaskPool.taskStatus=Constants.TASK_STATUS_DAICL;
						piccTaskPool.firstNumber=Integer.valueOf(Constants.TASK_SECOND_NUMBER);
						piccTaskPool.dsNumber=piccTaskPool.dsNumber+1;
						piccTaskPool.updateTime=dbTimeStamp;
						piccTaskPoolService.update(piccTaskPool);
					}else{
						piccTaskPool.taskStatus=Constants.TASK_STATUS_DAICL;
						piccTaskPool.firstNumber=Integer.valueOf(Constants.TASK_SECOND_NUMBER);
						piccTaskPool.dsNumber=piccTaskPool.dsNumber+1;
						piccTaskPool.updateTime=dbTimeStamp;
						piccTaskPoolService.updateSertIddd(piccTaskPool);
					}
					PiccTaskStatus piccTaskStatus = new PiccTaskStatus();
					piccTaskStatus.id = UUID.randomUUID().toString().replace("-", "");
					piccTaskStatus.taskId = taskId;
					piccTaskStatus.taskType = piccTaskPool.taskType;
					piccTaskStatus.taskStatus = Constants.TASK_STATUS_DAICL;
					piccTaskStatus.createTime = dbTimeStamp;
					piccTaskStatusService.insert(piccTaskStatus);
					stsMap.put("sts", "0");
					rep.getWriter().println(gson.toJson(stsMap));
					rep.getWriter().flush();
				}
			} else {
				stsMap.put("sts", "2");
				rep.getWriter().println(gson.toJson(stsMap));
				rep.getWriter().flush();
			}

		} catch (IOException e) {
			e.printStackTrace();
		}

		return null;
	}
	
}